<template>
	<view class="index">
		<musicHead title='网易云音乐' :icon="false"/>
		<view class="container">
			<scroll-view scroll-y="true" >
				<view class="search-bar">
					<text class="iconfont icon-fangdajing"></text>
					<input type="text" placeholder="搜索歌曲" @click="toSreach">
				</view>
				<view class="index-list">
					<view class="index-list-item" 
					v-for="item in topList" 
					:key="item.id"
					@click="handleToList(item.id)"
					:itemId='item.id'
					>
						<view class="list-item">
							<view class="index-list-img" >
								<image :src="item.coverImgUrl" mode=""></image>
								<text>每日更新</text>
							</view>
							<view class="index-list-text" >
								<view class="list-text" v-for="(item01, index) in item.tracks">{{index + 1}}.{{item01.first}}-{{item01.second}}</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import'@/common/iconfont.css'
	import musicHead from "../../components/MusicHead/MusicHead.vue"
	import {topList} from "../../common/api.js"
	export default {
		data() {
			return {
				topList : []
			}
		},
		methods: {
			// 跳转到list页面
			handleToList(id){
				uni.navigateTo({
					// 点击后进入不同的list界面
					url:'../list/list?id=' + id
				})
			},
			toSreach(){
				// 跳转到搜索歌曲页面
				uni.navigateTo({
					url:'../search/search'
				})
			}
		},
		components:{
			musicHead
		},
		onLoad() {
			// 网络请求，获取榜单数据
			topList().then((res) => {
				this.topList = res
			})
		}
	}
</script>

<style scoped>
	.search-bar{
		display: flex;
		align-items: center;
		height: 70rpx;
		margin: 70rpx 30rpx 30rpx 30rpx;
		background-color: #f7f7f7;
		border-radius: 50rpx;
	}
	.search-bar input{
		font-size: 28rpx;
		flex: 1;
	}
	.search-bar text{
		margin-left: 28rpx;
		font-size: 26rpx;
		margin-right: 26rpx;
	}
	.index-list{
		margin: 0 30rpx;
	}
	.index-list-item{
		display: flex;
		margin-bottom: 34rpx;
	}
	.list-item{
		display: flex;
	}
	.index-list-img{
		height: 212rpx;
		width: 212rpx;
		position: relative;
		border-radius: 30rpx;
		overflow: hidden;
		margin-right: 22rpx;
	}
	.index-list-img image{
		width: 100%;
		height: 100%;
	}
	.index-list-img text{
		position: absolute;
		left: 12rpx;
		bottom: 16rpx;
		color: white;
		font-size: 20rpx;
	}
	.index-list-text{
		width: 234px;
		
		display: flex;
		flex-direction: column;
	}
	.list-text{
		width: 234px;
		height: 32px;
		overflow: hidden;
		line-height: 32px;
		white-space: nowrap; 
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>
